using System.Data;
using System;
using Library.Business;
using NhatThanhSoftware;
namespace Library.Controller
{
    public partial class Controller_ThongTinGia_ChiTiet: Cls_ThongTinGia_ChiTiet
    {
        /// <summary>
        /// Set du lieu
        /// </summary>
        private static void setThongTinGia_ChiTiet(ref Cls_ThongTinGia_ChiTiet ThongTinGia_ChiTiet, DataRow dr)
        {
            ThongTinGia_ChiTiet.ID_ThongTinGia = Convert.ToInt32(dr[Cls_ThongTinGia_ChiTiet.fn_ID_ThongTinGia] ) ;
            ThongTinGia_ChiTiet.ID_LoaiHinhDoanhNghiep = dr[Cls_ThongTinGia_ChiTiet.fn_ID_LoaiHinhDoanhNghiep].ToString() ;
            ThongTinGia_ChiTiet.DonGia = Convert.ToDouble(dr[Cls_ThongTinGia_ChiTiet.fn_DonGia] ) ;
            ThongTinGia_ChiTiet.ThueGTGT = Convert.ToDouble(dr[Cls_ThongTinGia_ChiTiet.fn_ThueGTGT] ) ;
            ThongTinGia_ChiTiet.Thue_1 = Convert.ToDouble(dr[Cls_ThongTinGia_ChiTiet.fn_Thue_1] ) ;
            ThongTinGia_ChiTiet.Thue_2 = Convert.ToDouble(dr[Cls_ThongTinGia_ChiTiet.fn_Thue_2] ) ;
            ThongTinGia_ChiTiet.Thue_3 = Convert.ToDouble(dr[Cls_ThongTinGia_ChiTiet.fn_Thue_3] ) ;
            ThongTinGia_ChiTiet.Phi_1 = Convert.ToDouble(dr[Cls_ThongTinGia_ChiTiet.fn_Phi_1] ) ;
            ThongTinGia_ChiTiet.Phi_2 = Convert.ToDouble(dr[Cls_ThongTinGia_ChiTiet.fn_Phi_2] ) ;
            ThongTinGia_ChiTiet.Phi_3 = Convert.ToDouble(dr[Cls_ThongTinGia_ChiTiet.fn_Phi_3] ) ;
            ThongTinGia_ChiTiet.Hidden = Convert.ToBoolean(dr[Cls_ThongTinGia_ChiTiet.fn_Hidden] ) ;
        }
        /// <summary>
        /// Lưu dữ liệu
        /// </summary>
        /// <param name="dtData">Datatable</param>
        /// <returns>TRUE;FALSE</returns>
        public static bool doSAVE(DataTable dtData)
        {
            if (dtData.GetChanges() == null) return false;
            foreach( DataRow dr in dtData.GetChanges().Rows )
            {
                Cls_ThongTinGia_ChiTiet ThongTinGia_ChiTiet = new Cls_ThongTinGia_ChiTiet();
                try
                {
                    switch(dr.RowState)
                    {
                        case DataRowState.Modified:
                            setThongTinGia_ChiTiet(ref ThongTinGia_ChiTiet, dr);
                            ThongTinGia_ChiTiet.ID_find =Convert.ToInt32(dr[Cls_ThongTinGia_ChiTiet.fn_ID] );
                            ThongTinGia_ChiTiet.ID=ThongTinGia_ChiTiet.ID_find;
                            ThongTinGia_ChiTiet.doUpdate();
                            break;
                        case DataRowState.Added:
                            setThongTinGia_ChiTiet(ref ThongTinGia_ChiTiet, dr);
                            ThongTinGia_ChiTiet.doInsert();
                            break;
                        case DataRowState.Deleted:
                            ThongTinGia_ChiTiet.ID_find =Convert.ToInt32(dr[Cls_ThongTinGia_ChiTiet.fn_ID, DataRowVersion.Original] );
                            ThongTinGia_ChiTiet.doDelete();
                            break;
                    }
                }
                catch (Exception ex)
                {
                    ThongBao.msgThongBao(ThongTinGia_ChiTiet.ID + " chưa lưu được, click nút [OK] để lưu tiếp.");
                }
        }
        return true;
        }
        /// <summary>
        /// Check dữ liệu
        /// </summary>
        /// <param name="dtData">Datatable</param>
        /// <returns>TRUE;FALSE</returns>}
        public static void doCHECK(DataTable dtData)
        {
            if (dtData.GetChanges() == null) return;
            DataRowCollection drColection = dtData.GetChanges().Rows;
            foreach (DataRow dr in drColection)
            {
                if (dr.RowState == DataRowState.Deleted) break;
                string strID = dr[Cls_ThongTinGia_ChiTiet.fn_ID].ToString();
                if (dr.RowState == DataRowState.Added)
                {
                }
            }
        }
    }
}
